package com.jingdianjichi.wx.handler;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName:WxChatMsgFactory
 * Package:com.jingdianjichi.wx.handler
 * Description:
 *
 * @Author fst
 * @Create 2024/10/15 22:02
 * @Version 1.0
 */
@Component
public class WxChatMsgFactory implements InitializingBean
{
   @Resource
   private List<WxChatMsgHandler> wxChatMsgHandlerList;

   private Map<WxChatMsgTypeEnum,WxChatMsgHandler> handlerMap=new HashMap<>();

   public WxChatMsgHandler getHandlerByMsgType(String MsgType)
   {
       WxChatMsgTypeEnum msgTypeEnum =WxChatMsgTypeEnum.getMsgType(MsgType);
       return handlerMap.get(msgTypeEnum);
   }

    @Override
    public void afterPropertiesSet() throws Exception {
        for(WxChatMsgHandler wxChatMsgHandler:wxChatMsgHandlerList)
        {
            handlerMap.put(wxChatMsgHandler.getMsgType(),wxChatMsgHandler);
        }
    }
}
